package com.lrs.java.jdbc.jdbc_teacher;
import java.sql.*;
//可滚动的结果集
class TestScroll {
	public static void main(String args[]) {

		try {
			new oracle.jdbc.driver.OracleDriver();
			String url = "jdbc:oracle:thin:@localhost:1521:BJSXT";
			Connection conn = DriverManager
					.getConnection(url, "scott", "tiger");
			Statement stmt = conn.createStatement(
					ResultSet.TYPE_SCROLL_INSENSITIVE,
					ResultSet.CONCUR_READ_ONLY);
			ResultSet rs = stmt
					.executeQuery("select * from emp2 order by sal");
			rs.next();
			System.out.println(rs.getInt(1));
			rs.last();
			System.out.println(rs.getString(1));
			System.out.println(rs.isLast());
			System.out.println(rs.isAfterLast());
			//ResultSet.getRow() 会在某些（甚至全部）位置返回零。
			//这尤其意味着，使用已赋值的 ResultSet.last()、 ResultSet.getRow() 序列
			//在数据库中（甚至在同一数据库的驱动程序中）获取的行数不太可靠。
			//ResultSet.relative() 不会更改光标的位置
			System.out.println(rs.getRow());
			rs.previous();
			System.out.println(rs.getString(1));
			rs.absolute(6);
			System.out.println(rs.getString(1));
			rs.close();
			stmt.close();
			conn.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}